<% include("../../common/header.html",{title:"添加题目",active:4}){} %>
<!-- main start -->
<div class="surBox">
<!-- meanu start -->
<div class="top_menu">
	<div>
		<div class="mbar btn btn-default" id="qaBtn"><i class="glyphicon glyphicon-question-sign"></i> 问答题</div>
		<div class="mbar btn btn-default" id="sBtn"><i class="glyphicon glyphicon glyphicon-ok-circle"></i> 单选题</div>
		<div class="mbar btn btn-default" id="mBtn"><i class="glyphicon glyphicon-check"></i> 多选题</div>
		<div class="mbar btn btn-default" id="scBtn"><i class="glyphicon glyphicon-copyright-mark"></i> 单选+自定义</div>
		<div class="mbar btn btn-default" id="mcBtn"><i class="glyphicon glyphicon-subtitles"></i> 多选+自定义</div>
		<div class="mbar btn btn-default" id="ticBtn"><i class="glyphicon glyphicon-signal"></i> 投票题</div>
		<div class="mbar btn btn-default" id="otsBtn"><i class="glyphicon glyphicon-screenshot"></i> 其他扩展</div>
	</div>
	<div style="position: absolute; left: -50px; top:12px;">
    	<img src="${ctxPath}/static/image/newicon.gif">
    </div>
</div>
<!-- meanu end -->
<!-- 当前问卷展示 start -->
	<div class="current_survey">
		<div class="surveyhead">${survey.title}</div>
		<div>${survey.sdesc}</div>
		<div class="surveydescription"></div>
		<div id="qq"></div>
	</div>
<!-- 当前问卷展示 end -->
</div>
<!-- main end -->

<script type="text/javascript">
$(document).ready(function() {  
    $("#qq").load("${ctxPath}/manager/qaView/${survey.id}"); 
    
    var content = '<form id="questionBox" action="addQO" method="post">'+
	'<div class="title">题目标题<textarea class="form-control" name="head" id="head" rows="2"></textarea></div>'+
	'<div class="add_remove_btn"><button type="button" class="btn btn-default" id="addButton"><i class="glyphicon glyphicon-plus"></i> 新增选项</button><br/><br/><button type="button" class="btn btn-default" id="removeButton"><i class="glyphicon glyphicon-minus"></i> 删除选项</button></div>'+
	'<div id="answer">'+
	'<div id="as0">选项A <input type="text" calss="addInput" name="contentA" id="contentA" value="选项A" />'+
	'<input type="hidden" name="orderNumA" id="orderNumA" value="0"/></div>'+
	'</div>'+
	'<input type="hidden" name="surveyId" id="surveyId" value="${survey.id}"/>'+
	'<input type="hidden" name="type" id="type" value="1"/>'+
	'<button type="button" id="addQustion" onclick="checkAndSubmit();" class="btn btn-success btn-block">添加当前题目</button></form>';
	
    // 单选按钮开启单选浮层
    $("#sBtn").click(function (e)
		{  
	        layer.open({
	            type: 1,
	            title: '新增单选题',
	            closeBtn: 1,
	            shadeClose: false,
	            area: ['600px', '400px'],
	            skin: 'editQuestionBox',
	            content: content
	        });
	    	add();
		}); 
    
    // 多选按钮开启单选浮层
    $("#mBtn").click(function (e)
		{  
	        layer.open({
	            type: 1,
	            title: '新增多选题',
	            closeBtn: 1,
	            shadeClose: false,
	            area: ['600px', '400px'],
	            skin: 'editQuestionBox',
	            content: content
	        });
	        $("#type").val(2);
	    	add();
		});   
    
    
    
//------- 创建单选或多选题 start -----   
    function add(){
        var MaxInputs       = 6; //最多6个选项
        var options = ["A","B","C","D","E","F"]; 
        var x =  $("#answer").length; //初始化当前选项框数量
        $("#addButton").click(function (e)  //新增选项
            {  
                    if(x < MaxInputs) 
                    {  
                        option = options[x]
                        //新增选项
                        $("#answer").append('<div id="as' + x +'">选项 ' + option + '<input type="text" name="content'+ option + '" id="content'+ option +'" value="选项'+ option +'"/>'
                                +'<input type="hidden" name="orderNum' + option + '" id="orderNum' + option + '" value="' + x + '"/></div>');  
                        x++; //text box increment  
                    }  
            return false;  
            });  
                 
        	$("#removeButton").click(function (e)  //删除选项
        	{  
        	    nubmer = x -1;
        	    if( nubmer >= 1 ) { 
                    $("#as" + nubmer).remove();  
                    x --; 
            	}  
        	return false;  
        	}); 
    }
//------- 创建单选或多选题 end -----
    


});  

/** 校验及数据提交  **/
function checkAndSubmit(){
    $.post(
			"${ctxPath}/manager/addQO",
			$("#questionBox").serialize(),
			function(data) {
			    layer.msg(data.msg);
			    if(!data.status) {
    			   if(data.others != null){
    			       jQuery.each(data.others, function(i,item){  
    		                layer.tips(item.message, "#" + item.field ,{
    		        	        tips: [2, '#78BA32'] ,tipsMore: true,time: 5000
    		        	    }); 
    		            });  
    			   }
    			}
			    $("#qq").load("${ctxPath}/manager/qaView/${survey.id}"); 
			},
	    	"json"
		);
}

</script>

</div>
</body>
</html>